import numpy as np
import mandelbrot as mdb
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
import plotly.io as pio
from sys import argv as argv

## 迭代次数
n = eval(argv[1])
## 矩形区域端点
z = eval(argv[2])
w = eval(argv[3])

## 输出矩阵区域内的Mandelbrot集
def mandelbrot():
    global z,w,n
    return mdb.generate_Mandelbrot_in_dec(z,w,n)
ans = mandelbrot()

## 显示Mandelbrot集
fig = px.imshow(ans[0], origin="lower", x=ans[1], y=ans[2]) #设置非矩阵显示模式, 并自定义坐标轴
fig.update_layout(
    title = dict(
        text = "Mandelbrot Set, N = "+str(n),
    )
)

## 输出png,需要下载包 kaleido (可运行pip install -U kaleido)
pio.write_image(fig,"n_"+str(n)+argv[4]+".png")
